﻿/******************************************************************
** 文 件 名: BD_ContractChange_Edit.aspx.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-3-15 19:35:24
** 描    述: 合同变更情况编辑页面
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Honestysoft.BaseLibrary;
using Honestysoft.BaseObject;
using Honestysoft.BaseLibrary.ExceptionHandling;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;
using System.Data.Common;


namespace Honestysoft.Financing.WebUI.Module.Contract
{
	public partial class BD_ContractChange_Edit : Page
	{	
		protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
				BindControl();
                Bind();
            }
        }
		
		private void BindControl()
		{
		}

        private void Bind()
        {
            numSourceMoney.Text = Request.QueryString["CurChangePrice"];
            hidSponsor.Value = UserLoginer.LoginUser.ID;
            txtSponsorName.Text = UserLoginer.LoginUser.Name;
            dtpCreateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            dtpChangeDate.Text = DateTime.Today.ToString("yyyy-MM-dd");
            hidLastChangeDate.Value = Request.QueryString["LastChangeDate"];
        }
		
		protected void btnOK_Click(object sender, EventArgs e)
        {
            Add();
        }

        /// <summary>
        /// 新增
        /// </summary>
        private void Add()
        {
            try
            {
                BD_ContractChange obj = GetSubmitObject();
                //if (Utils.ContractSession.Contract.ContractChanges == null)
                //{
                //    Utils.ContractSession.Contract.ContractChanges = new System.Collections.Generic.List<BD_ContractChange>();
                //}
                //Utils.ContractSession.Contract.ContractChanges.Insert(0,obj);
                //Utils.ContractSession.Contract.RefreshChange();
                string json = JsonHelper.JsonSerializer<BD_ContractChange>(obj);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "window.returnValue='" + Server.UrlEncode(json) + "';window.close();", true);
                
                //ScriptHelper.Window.AlertClose("保存成功！", true);
            }
            catch (BaseException bex)
            {
                ExceptionHelper.ExceptionDistribute(bex, false);
                ScriptHelper.Window.Alert(bex.Message);
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("保存失败！系统发生了未知错误！");
            }
        }
		/// <summary>
        /// 得到提交对象
        /// </summary>
        /// <returns></returns>
        private BD_ContractChange GetSubmitObject()
        {
            BD_ContractChange obj = new BD_ContractChange();
            obj.ID = Honestysoft.BaseLibrary.Common.Guid.GetGuid();
            obj.ContractID = Request.QueryString["ContractID"];
			if(numSourceMoney.Text.Trim().Length > 0){obj.SourceMoney = Convert.ToDecimal(numSourceMoney.Text);}
			if(numChangeMoney.Text.Trim().Length > 0){obj.ChangeMoney = Convert.ToDecimal(numChangeMoney.Text);}
			if(dtpChangeDate.Text.Trim().Length > 0){obj.ChangeDate = Convert.ToDateTime(dtpChangeDate.Text);}
            obj.Sponsor = hidSponsor.Value;// txtSponsor.Text;
			obj.SponsorName =  Server.UrlEncode(txtSponsorName.Text);
			if(dtpCreateTime.Text.Trim().Length > 0){obj.CreateTime = Convert.ToDateTime(dtpCreateTime.Text);}
            obj.IsConfirm = true;// chkIsConfirm.Checked;
            obj.Remark = Server.UrlEncode(txtRemark.Text);
            obj.dataState = EnumItem.DataState.New;
            return obj;
        }
	}
}